package HomeWork;

public class Bank implements Runnable{
    private  int count = 1000;
    //   Object obj = new Object();
    @Override
    public  void run()
    {
        while(true)
        {
            synchronized(this) {
                if(count>0)
                {
                    try{
                        Thread.sleep(100);
                    }catch(Exception e){
                        e.printStackTrace();
                    }
                    count = count -100;
                    System.out.println(Thread.currentThread().getName()+" 取走100元还剩"+count+"元");
                }
                else System.exit(0);
            }
        }
    }
}
class  TicketDemo_runnable
{
    public static void main(String[] args) {
        Bank t = new Bank ();
        Thread t1 = new Thread(t,"A");
        Thread t2 = new Thread(t,"B");

        t1.start();
        t2.start();
    }
}